﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace EF4.Core.Models.Entities
{
    public abstract class EntityBase
    {
        public bool IsValid
        {
            get {
                return !Validate().HasViolations;
            }
        }
        public EntityValidationResult Validate()
        {
            var validationResults = new List<ValidationResult>();
            var vc = new ValidationContext(this, null, null);
            var isValid = Validator.TryValidateObject(this, vc, validationResults,true);

            return new EntityValidationResult(validationResults);
        }

        //protected EntityValidationResult ValidateEntity<T>(T entity)
        //where T : EntityBase
        //{
        //    return new EntityValidator<T>().Validate(entity);
        //}

        //protected EntityValidationResult ValidateEntity()
       
        //{
        //    return new EntityValidator<this.GetType()>().Validate(this);
        //}
    }
}

